<template>
	<view class="content">
		<view class="tabList">
			<text :class="suo == index?'active':''" @click="changeTab(index)" v-for="(item,index) in tabList"
				:key="index">{{item}}</text>
		</view>

		<view class="joinBox" v-if="suo == 0">
			<view class="joinWrap">
				<view class="joli">
					<label>姓名：</label>
					<view class="joinInput">
						<input type="text" v-model="joinForm.name" placeholder="请输入" />
					</view>
				</view>

				<view class="joli">
					<label>联系方式：</label>
					<view class="joinInput">
						<input type="text" v-model="joinForm.phone" placeholder="请输入" />
					</view>
				</view>
			</view>

			<view class="joinWrap">
				<view class="joli">
					<label>应聘职位：</label>
					<view class="joinInput">
						<input type="text" v-model="joinForm.position" placeholder="请输入" />
					</view>
				</view>
				<view class="joli">
					<label>上传简历：</label>
					<view class="uploadBox">
						<u-upload
							style="display: flex;justify-content: center;"
							width="100rpx"
							height="100rpx"
							accept="all"
							:capture="['album', 'camera']"
							@afterRead="afterRead"
							@delete="deletePic"
							:fileList="fileList"
							name="1"
						>
							<view class="uppLoadd">点击上传简历</view>
						</u-upload>

					</view>

				</view>
			</view>

		</view>

		<view class="joinBox" v-if="suo == 1">
			<view class="joinWrap">
				<view class="joli">
					<label>企业名称：</label>
					<view class="joinInput">
						<input type="text" v-model="bussForm.enterpriseName" placeholder="请输入" />
					</view>
				</view>

				<view class="joli">
					<label>企业地址：</label>
					<view class="joinInput">
						<input type="text" v-model="bussForm.address" placeholder="请输入" />
					</view>
				</view>

				<view class="joli">
					<label>姓名：</label>
					<view class="joinInput">
						<input type="text" v-model="bussForm.contactName" placeholder="请输入" />
					</view>
				</view>

				<view class="joli">
					<label>联系方式：</label>
					<view class="joinInput">
						<input type="number" v-model="bussForm.contactPhone" placeholder="请输入" />
					</view>
				</view>
			</view>

			<view class="joinWrap">
				<view class="joli joli2">
					<label>合作意向：</label>
					<textarea name="" v-model="bussForm.description" id="" cols="30" rows="10"></textarea>
				</view>
			</view>
		</view>


		<view class="twoBotom">
			<view class="twoBtn" @click="goForm">
				提交
			</view>
		</view>

	</view>
</template>

<script>
	import baseUrl from '@/util/config.js';
	import {
		addRecruit,
		addBuss,
		getUserInfoDetail
	} from '@/api/login.js';
	import moment from 'moment';
	export default {
		data() {
			return {
				suo: 0,
				tabList: ['加盟合作', '商务合作'],
				fileList: [],
				bussForm: {
					contactName: '',
					contactPhone: '',
					description: '',
					enterpriseName: '',
					address: ''
				},
				joinForm: {
					name: '',
					phone: '',
					position: '',
					resume: '',
					status: 0
				}
			}
		},
		onLoad(opt) {
			if (opt.type == 1) {
				this.suo = 1;
			} else {
				this.suo = 0;
			}
		},
		methods: {
			afterRead(event) {
				let wenList = event.file;
				uni.uploadFile({
					url: baseUrl.baseUrl + '/common/upload',
					filePath: wenList.url,
					name: 'file',
					header: {
						Authorization: 'Bearer ' + uni.getStorageSync('userToken')
					},
					success: res => {
						var jsurl = JSON.parse(res.data)
						console.log(jsurl);
						this.fileList = [];
						this.joinForm.resume = jsurl.url;
						let objj = {
							url: jsurl.url
						};
						this.fileList.push(objj);
					}
				});
			},
			deletePic() {
				console.log(123431234);
				this.fileList = [];
				this.joinForm.resume = '';
			},
			changeTab(index) {
				this.suo = index;
			},
			goForm() {
				if (this.suo == 0) {
					if (this.joinForm.name == '') {
						return uni.$u.toast('请输入姓名!');
					}
					if (this.joinForm.phone == '') {
						return uni.$u.toast('请输入联系方式!');
					}
					if (uni.$u.test.mobile(this.joinForm.phone) == false) {
						return uni.$u.toast('联系方式格式有误!');
					}
					addRecruit(this.joinForm).then(res => {
						if (res.code == 200) {
							uni.$u.toast('操作成功!');
							// Object.keys(this.joinForm).forEach(item=>{
							// 	this.joinForm[item] = '';
							// });
							uni.navigateBack({
								delta: 1
							})
						} else {
							uni.$u.toast(res.msg);
						}
					})
				} else {
					if (this.bussForm.enterpriseName == '') {
						return uni.$u.toast('请输入企业名称!');
					}
					if (this.bussForm.address == '') {
						return uni.$u.toast('请输入企业地址!');
					}
					if (this.bussForm.contactName == '') {
						return uni.$u.toast('请输入姓名!');
					}
					if (this.bussForm.contactPhone == '') {
						return uni.$u.toast('请输入联系方式!');
					}
					if (uni.$u.test.mobile(this.bussForm.contactPhone) == false) {
						return uni.$u.toast('联系方式格式有误!');
					}
					addBuss(this.bussForm).then(res => {
						if (res.code == 200) {
							uni.$u.toast('操作成功!');
							// Object.keys(this.bussForm).forEach(item=>{
							// 	this.bussForm[item] = '';
							// });
							uni.navigateBack({
								delta: 1
							})
						} else {
							uni.$u.toast(res.msg);
						}
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uppLoadd {
		@include baseFont(30rpx, #3671E9, 112rpx);
	}

	.content {
		background-color: #F5F5F5;
		min-height: 100vh;

		.joinBox {
			padding: 0 24rpx;

			.joinWrap {
				background-color: #fff;
				border-radius: 12rpx;
				margin-bottom: 16rpx;

				.joli {
					@include flx;
					justify-content: space-between;
					padding: 0 32rpx;
					border-bottom: 1px solid #F0F0F0;
					align-items: center;

					label {
						display: block;
						@include baseFont(30rpx, #333, 112rpx);
						width: 25%;
					}

					.joinInput {
						width: 75%;

						input {
							@include baseFont(30rpx, #333, 112rpx);
							height: 112rpx;
							text-align: right;
							display: block;
						}
					}

					.uploadBox {
						.uppLoadd {
							padding-left: 44rpx;
							background: url('../../static/upload.png') no-repeat left center;
							background-size: 32rpx 25rpx;
						}
					}
				}

				.joli2 {
					display: inherit;
					padding-bottom: 32rpx;

					label {
						line-height: 42rpx;
						margin-bottom: 14rpx;
						padding-top: 32rpx;
					}

					textarea {
						display: block;
						background-color: #F6F6F6;
						height: 80rpx;
						@include baseFont(30rpx, #333, 42rpx);
						border-radius: 8rpx;
						width: calc(100% - 40rpx);
						padding: 20rpx;
					}
				}
			}
		}

		.tabList {
			@include flx;
			justify-content: center;
			padding: 24rpx 0;

			text {
				display: block;
				@include baseFont(32rpx, #333, 44rpx);
				position: relative;
				padding-bottom: 18rpx;
			}

			text:first-of-type {
				margin-right: 128rpx;
			}

			.active {
				color: #3671E9;
			}

			.active::after {
				content: '';
				background-color: #3671E9;
				width: 52rpx;
				height: 6rpx;
				border-radius: 3rpx;
				position: absolute;
				bottom: 0;
				left: 50%;
				transform: translateX(-50%);
			}
		}
	}
</style>